<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\user;

use App\Dao\IntegralDetailDao;
use App\Kernel\Util\UserJwtInstance;
use App\Middleware\User\UserMiddleware;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 钱包控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\admin
 */
class WalletController extends Controller
{
    /**
     * @Inject
     * @var IntegralDetailDao
     */
    private $integral_detail_dao;

    /**
     * 用户积分接口
     *
     * @author 刘兴永(aile8880@qq.com)
     * @date 2020-02-22 19:57:00
     */
    public function integral()
    {
        $user = UserJwtInstance::instance()->build()->getUser();

        $integral_detail = $this->integral_detail_dao->get([
            'user_id' =>$user->id
        ]);

        $this->success([
            'integral' => $user->integral,
            'integral_detail' => $integral_detail
        ]);
    }

    /**
     * 用户余额接口
     *
     * @author 刘兴永(aile8880@qq.com)
     * @date 2020-02-22 19:57:00
     */
    public function money()
    {
        $user = UserJwtInstance::instance()->build()->getUser();

        $this->success([
            'money' => number_format($user->money, 2)
        ]);
    }
}